#pragma once

#include <mutex>

template <class T>
ref class SingletonRef
{
public:
	static T^ Instance()
	{
		static T^ smInstance = nullptr;
		static std::mutex smMutex;

		smMutex.lock();
		if(smInstance == nullptr)
		{
			smInstance = ref new T();
		}
		smMutex.unlock();
		return smInstance;
	}

};

template <class T>
class Singleton
{
public:
	static T* Create()
	{
		if(smInstance == nullptr)
		{
			smInstance = new T();
		}
		return smInstance;
	}

	static T* Instance()
	{
		return smInstance;
	}

	static void Destory()
	{
		if(smInstance)
		{
			delete smInstance;
		}
	}

	static T* smInstance;

protected:
	Singleton(){};
	
	~Singleton(){};
	
	Singleton(const Singleton&){}

	Singleton& operator= (const Singleton &){}


};

template <class T>
T* Singleton<T>::smInstance = NULL;